$(document).ready(function(e) {

  $("#loginorsignup").click(function() {
    $(".logbox").addClass("activelogbox");
  });
  $(".logbox").mouseup(function() {
    return false;
  });
  $(this).mouseup(function(x) {
    if($(x.target).parent(".logbox").length == 0) {
      $(".logbox").removeClass("activelogbox");

    }

  });
  $(window).scroll(function(event) {
    $(".logbox").removeClass("activelogbox");
  });
  /*silod轮播*/
  var unslider04 = $('#hdslide').unslider({
      fluid: true,
      dots: true,
      speed: 400,
      delay: 3000,
      pause: false,
      starting: function() {
        var top = $(window).scrollTop();
        if(top) {
          data04.stop();
        }
      }
    }),
    data04 = unslider04.data('unslider');

  $('.unslider-arrow04').click(function() {
    var fn = this.className.split(' ')[1];
    data04[fn]();
  });
  /*    	var windowHeight = $(window).height();
    if($(".header").height() < windowHeight){
        $(".header").height(windowHeight);
    }
     if($(".banner ul li").height() < windowHeight){
        $(".banner ul li").height(windowHeight);
    }*/
  /*ip-desc*/
  var copyLi1 = $('.center1').find('li');
  var copyLi2 = $('.center2').find('li');
  copyLi1.each(function(index, value) {
    $(value).mouseover(function(e) {
      $('.center1').addClass('centerhover');
      e.stopPropagation();
    });
    $(value).mouseout(function(e) {
      $('.center1').removeClass('centerhover');
      e.stopPropagation();
    });
  });
  copyLi2.each(function(index, value) {
    $(value).mouseover(function(e) {
      $('.center2').css('animation-play-state', 'paused');
      e.stopPropagation();
    });
    $(value).mouseout(function(e) {
      $('.center2').css('animation-play-state', 'running');
      e.stopPropagation();
    });
  });

  /*home-app*/
  var appAs = $('#tabApp').find('a');
  appAs.each(function(index, value) {
    $(value).click(function(e) {
      leaderMove(value);
      tabPanelMove(value);
      e.stopPropagation();
    });
  });

  function leaderMove(obj) {
    var currA = $('.tab-tab .active');
    currA.removeClass('active');
    $(obj).addClass('active');
    var fristLeft = $(appAs[0]).offset().left;
    var currLeft = $(obj).offset().left - fristLeft;
    var currWidth = $(obj).outerWidth();
    var tabLine = $('#tabLine');
    tabLine.css({
      'transform': 'translateX(' + currLeft + 'px)',
      'width': currWidth + 'px'
    });
  }

  function tabPanelMove(obj) {
    var ilId = $(obj).data('rel');
    var currPanel = $('.tab-panel .active');
    currPanel.removeClass('active');
    $('#' + ilId).addClass('active');
  }

  /*barX*/
  $(window).scroll(function() {
    var top = $(window).scrollTop();

    if(top != 0) {
      addFixed(top);
      addData();
      data04.stop();
    } else {
      removeFixed();
      removeData()
      setTimeout(function() {
        data04.play();
      }, 1000);
    }

  });

  function addData() {
    $(".header").css("height", "148px");
    $(".banner ul li").css("height", "148px");
    $(".banner").css("height", "148px");
/*    $(".data").removeClass("fadeOutDown animated");
    $(".data").addClass("fadeInUp animated");

    $("#banner-img").removeClass("fadeOutDown animated");
    $("#banner-img").addClass("fadeInUp animated");*/
  }

  function removeData() {
    $(".header").css("height", "100vh");
    $(".banner ul li").css("height", "100vh");
    $(".banner").css("height", "100vh");
/*    $(".data").removeClass("fadeInUp animated");
    $(".data").addClass("fadeOutDown animated");

    $("#banner-img").removeClass("fadeInUp animated");
    $("#banner-img").addClass("fadeOutDown animated");*/

  }

  function addFixed(top) {
    $('#barX').addClass('barX-fixed');
    if(top <= 50) {
      $('#barX').css('opacity', top * top * 0.001);
    } else {
      $('#barX').css('opacity', '1');
    }
  }

  function removeFixed() {
    $('#barX').removeClass('barX-fixed');
    $('#barX').css('opacity', '1');
  }

  function changeActive(top) {
    var currentId = '';
    $('.page>div[id]').each(function(index, value) {
      var itemTop = $(value).offset().top;
      if(itemTop - 150 < top) {
        currentId = '#' + $(value).attr('id'); /*不带#*/
      } else {
        return false;
      }
    });
    currentActive = $('#nav .active');
    if(currentId && currentActive.attr('href') != currentId) {
      currentActive.removeClass('active');
      $('[href=' + currentId + ']').addClass('active');
    }
  }
  /*barX-a*/
  $('.nav>a').each(function(index, value) {
    $(value).click(function(e) {
      e.preventDefault();

      var aId = $(this).attr('href');
      var top = $(aId).offset().top - 74;
      var topwindow = $(window).scrollTop();
      console.log(top,topwindow)
      if(topwindow == 0){
      	top = top - $(".header").height()+74*2;   	
      }
      console.log(top)
      $('html,body').animate({
        scrollTop: top
      }, 'slow', 'swing');
    });
  });

  /*brand*/
  var $brandNav = $('#brandNavX');
  var activeA = $brandNav.find('a:first');
  var timer
  var $brandDesc = $('#brandDesc');
  var Dindex
  var PrevDindex
  var PrevLi
  var ActiveLi
  $brandNav
    .on('mouseenter', 'a', function(e) {
      if(timer) {
        clearTimeout(timer);
      }
      timer = setTimeout(function() {
        activeA.removeClass('active');
        PrevDindex = activeA.data('index') - 1;
        PrevLi = $brandDesc.find('il:eq(' + PrevDindex + ')');
        PrevLi.removeClass('in').addClass('out');
        if($(e.target).get(0).tagName === 'A') {
          activeA = $(e.target).addClass('active');
        } else {
          activeA = $(e.target).parents('a').addClass('active');
        }
        Dindex = activeA.data('index') - 1;
        ActiveLi = $brandDesc.find('il:eq(' + Dindex + ')');
        if(PrevDindex <= Dindex) {
          PrevLi.removeClass('revers');
          ActiveLi.removeClass('out revers').addClass('in');
        } else if(PrevDindex > Dindex) {
          PrevLi.addClass('revers');
          ActiveLi.removeClass('out').addClass('in revers');
        }
      }, 250);
    })

  function textstudent(a) {
    $(".intext.fadeInDown").removeClass("fadeInDown");
    $(".intext.fadeOutDown").removeClass("fadeOutDown")
    $(".intext.fadeInUp").removeClass("fadeInUp")
    $(".intext.fadeOutUp").removeClass("fadeOutUp")
    $(".intext.animated").removeClass("animated")
    var index_img = $(".img4").attr("index-img");
    var textative = $(".intext.textative");
    var toative = $(".intext").eq(parseInt(index_img) - 1);

    if(a > 0) {
      toative.addClass("textative");
      toative.addClass("fadeInDown animated");
      textative.addClass("fadeOutDown animated");
      textative.removeClass("textative");

    } else {
      toative.addClass("textative");
      toative.addClass("fadeInUp animated");
      textative.addClass("fadeOutUp animated");
      textative.removeClass("textative");
    }

  }
  var toleft = function() {
    $(".img").each(function() {
      var index = $(this).attr("index-css");
      var count = parseInt(index);
      $(this).removeClass("img" + index)

      if(count == 1) {
        $(this).addClass("img7");
        $(this).attr("index-css", 7)
      } else {
        $(this).addClass("img" + (count - 1))
        $(this).attr("index-css", (count - 1))
      }
    })
    textstudent(1);
  }
  var toright = function() {
    $(".img").each(function() {
      var index = $(this).attr("index-css");
      var count = parseInt(index);
      $(this).removeClass("img" + index)

      if(count == 7) {
        $(this).addClass("img1");
        $(this).attr("index-css", 1)
      } else {
        $(this).addClass("img" + (count + 1))
        $(this).attr("index-css", (count + 1))
      }
    })
    textstudent(-1);

  }
  var school01 = setInterval(toleft, 3000)
  $('#fantastic img')
    .on('mouseover', function() {
      clearInterval(school01);
    })
    .on('mouseout', function() {
      school01 = setInterval(toleft, 3000)
    })
    .on('click', function() {
      /*  $("#fantastic img").unbind('click')	*/
      var img_css = $(this).attr('index-css');
      console.log(img_css);
      var changetimes = parseInt(img_css) - 4;
      console.log(changetimes);
      if(changetimes > 0) {
        for(var i = 0; i < Math.abs(changetimes); i++) {
          toleft();
        }
      } else {
        for(var i = 0; i < Math.abs(changetimes); i++) {
          toright();
        }
      }
    });

});